import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
	state: () => {
		return { 
			userInfo: {} as any,
			unionid: '',
			wxUserInfo: {} as any
		};
	},
	getters: {
		getToken: state => {
			return state.userInfo || {}
		},
		getUnionid: state => {
			return state.unionid || ''
		},
		getUserInfo: state => {
			return state.userInfo || {}
		},
		getWxUserInfo: state => {
			return state.wxUserInfo || {}
		},
		isBingPhone: state => {
			const userInfo = state.userInfo || {}
			return !!userInfo.phone
		}
	},
	actions: {
		setUserInfo (userInfo: any) {
			this.userInfo = userInfo
		},
		setWxUserInfo (wxUserInfo: any) {
			this.wxUserInfo = wxUserInfo
		},
		setUnionid (unionid: any) {
			this.unionid = unionid || ''
		}
	}
});